package com.example.springboot_code_read.beanDefinitionRegistry;

import com.example.springboot_code_read.bean.MyBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;

public class BeanDefinitionRegistryTest {

    public static void main(String[] args) {

        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(MyBean.class);

        beanFactory.registerBeanDefinition("myBean", beanDefinition);

        BeanDefinition bean = beanFactory.getBeanDefinition("myBean");
        System.out.println("bean is " + bean);

        boolean hasMyBean = beanFactory.containsBeanDefinition("myBean");
        System.out.println("has mybean " + hasMyBean);

        String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
        System.out.println("names is " + String.join("," , beanDefinitionNames));

        int beanDefinitionCount = beanFactory.getBeanDefinitionCount();
        System.out.println("bean count is " + beanDefinitionCount);

        boolean isBeanNameInUse = beanFactory.isBeanNameInUse("myBean");
        System.out.println("is BeanName In Use " + isBeanNameInUse);

        beanFactory.removeBeanDefinition("myBean");
        System.out.println("bean has remove");

        boolean hasMyBean1 = beanFactory.containsBeanDefinition("myBean");
        System.out.println("has mybean " + hasMyBean1);


    }

}
